package cn.gson.springboot.controller;


import cn.gson.springboot.model.mapper.QaMapper;
import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.pojos.Qa;
import cn.gson.springboot.model.service.QaService;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.aspectj.apache.bcel.classfile.Module;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class QaController {
    @Autowired
    QaService qaService;

    @RequestMapping("/qa-list")
    @ResponseBody
    public Map<String,Object> qaList(Integer page,Integer size, String search,Integer type) {

        Page<Object> obj = PageHelper.startPage(page, size);
        List<Qa> qa = qaService.selectAll(search,type);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());//返回总页数
        map.put("rows",qa);//返回查到的数据
        return map;
    }
    @RequestMapping("/qa-all-list")
    @ResponseBody
    public  List<Qa> qaList( String search,Integer type) {
        List<Qa> qa = qaService.selectAll(search,type);
        return qa;
    }

    @RequestMapping("/qa-deleteOne")
    @ResponseBody
    public void deleteOne() {
         qaService.deleteOne(3);
    }

    /*@RequestMapping("/qa-selectByQatype")
    @ResponseBody
    public Map<String,Object> selectByQatype(Integer page,Integer size,Integer type) {
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Qa> qa = qaService.selectByQatype(type);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());//返回总页数
        map.put("rows",qa);//返回查到的数据
        return map;
    }*/

    @RequestMapping("/qa-alter")
    @ResponseBody
    public void alter() {
        Qa qa = new Qa();
        qa.setQaQuestion("你喜欢gg吗？");
        qa.setQaAnswer("不喜欢");
        qaService.alter(1,qa);

    }

    @RequestMapping("/qa-addQa")
    @ResponseBody
    public void addQa(@RequestBody Qa qa) {
        System.out.println(qa);
        qaService.addQa(qa);
    }
}